package com.mls.fivedistrict.controller.portal;


import com.mls.fivedistrict.common.ServiceResponse;
import com.mls.fivedistrict.controller.BaseController;
import com.mls.fivedistrict.pojo.UserVote;
import com.mls.fivedistrict.pojo.UserVoteOption;
import com.mls.fivedistrict.pojo.UserVoteRequest;
import com.mls.fivedistrict.server.UserVoteService;
import com.mls.fivedistrict.util.validator.BeanValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 用户投票关系表 前端控制器
 * </p>
 *
 * @author Five Team
 * @since 2018-05-21
 */
@RestController
@RequestMapping("/api/app")
public class UserVoteController extends BaseController {
    @Autowired
    private UserVoteService userVoteService;

    @PostMapping("/v1/userVote")
    public ServiceResponse userVote(@RequestBody UserVoteRequest userVoteRequest) {
        BeanValidator.check(userVoteRequest);
        userVoteRequest.setUserId(getUser().getId());
        boolean result = userVoteService.vote(userVoteRequest, getUser());
        if (!result) {
            return ServiceResponse.createErrorResponse("服务器忙，请等待再投");
        }
        return ServiceResponse.createSuccessResponse("投票成功");
    }

}

